# forward-compat boilerplate
from __future__ import absolute_import
from __future__ import with_statement
__metaclass__ = type

import os
import string
import random

USABLE_PUNCTUATION = '''~!@#$%^&*()-=+[];:'",.<>?'''


def randint(max):
    return random.randint(0, max)


class Generator:
    def __init__(self, words):
        self.words = words
        self.digits = string.digits
        self.punct = USABLE_PUNCTUATION

    def getword(self, min=1, max=100):
        word = ''
        while len(word) < min or len(word) > max:
            word = random.choice(self.words)
        return word

    def generate(self, minlen=8):
        words = [self.getword(5,12),
                 self.getword(3,6)]
                 #self.getword(1,4)]

        i = randint(1)
        words[i] = words[i].capitalize()

        pun = random.choice(self.punct)
        num = str(randint(10**randint(2)))

        joins = [pun, num]

        out = words.pop()
        out += joins.pop(randint(1))
        out += words.pop()
        #out += joins.pop()
        #out += words.pop()

        while len(out) < minlen:
            out += random.choice(self.digits + self.punct)
            out += random.choice(self.words)
        return out

    __repr__ = __str__ = __call__ = generate

def open_file(name='words'):
    fname = name + '.txt'
    if not os.path.isabs(fname):
        d = os.path.dirname(__file__)
        fname = os.path.join(d, fname)
    words = map(string.strip, open(fname))
    return Generator(words)


if __name__ == '__main__':
    print open_file().generate()
